package serverside;

import javax.swing.*;

import java.awt.Toolkit;
import java.awt.*;
import java.awt.event.*;



public class Jp extends JPanel {
    public int b = 0 , u = 0;
    private JTextField t = new JTextField("", 30);
    private JTextField t2 = new JPasswordField("", 30);
    private JButton login = new JButton("Login");
    private JButton back = new JButton("Back");
    private JLabel username, password;
    private JLabel label = new JLabel("");
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    Font font = new Font("Arial", Font.BOLD, 12);
    public String uname,pw;
    public String getS(String s , String a){
        s = a;
        return s;
    }
    
    public void clear(){
        label.setText("");
        t.setText("");
        t2.setText("");
    }
    
    
    public Jp(){
        label.setBounds(450, 50, 300, 40);
        label.setFont(font);
        dim.width = 900;
        dim.height = 400;
        setOpaque(false);
        setPreferredSize(dim);
        setEnabled( true );
        //setBackground(Color.blue);
        setLayout(null);
        
        username = new JLabel("Username");
        username.setBounds(70, 50, 60, 30);
        username.setForeground(Color.white);
        username.setEnabled( true );
        add(username);
        
        
        password = new JLabel("Password");
        password.setBounds(70, 100, 60, 30);
        password.setForeground(Color.white);
        password.setEnabled( true );
        add(password);
        
        
        t.setBounds(190, 50, 200, 30);
        t.setEnabled( true );
        t.setFont(font);
        t.setForeground(Color.BLUE);
        add(t);
        t.addMouseListener(new MouseAdapter(){
            public void mousePressed(MouseEvent e) {
                t.setText("");
            }
        });
        
        
        t2.setBounds(190, 100, 200, 30);
        t2.setEnabled( true );
        t2.setFont(font);
        t2.setForeground(Color.BLUE);
        add(t2);
        t2.addMouseListener(new MouseAdapter(){
            public void mousePressed(MouseEvent e) {
                t2.setText("");
            }
        });
        
        
        back.setBounds(190, 150, 100, 25);
        back.setEnabled( true );
        add(back);
        
        login.setBounds(290, 150, 100, 25);
        login.setEnabled( true );
        add(login);
        
        updateUI();
        login.addMouseListener(new MouseAdapter(){
            String s,p;
            public void mousePressed(MouseEvent e) {
                if (e.getButton() == MouseEvent.BUTTON1)
                {
                    String st = "";
                    s = getS(st,t.getText());
                    st = "";
                    p = getS(st,t2.getText());
                    add(label);
                    if(s.length() > 0 && p.length() > 0)
                    {
                        if(s.equals("hooss_2008") && p.equals("44449231")){
                            JOptionPane.showMessageDialog(null , "Welcome Mr. Admin");
                            label.setText("Mr. Admin");
                            u = 1;
                            uname = s;
                            label.setForeground(Color.yellow);

                            updateUI();
                        }
                        else
                        {
                            JOptionPane.showMessageDialog(null , "Wrong username or password !");
                            label.setText("Write username or password correctly" );
                            u = 2;
                            uname = "";
                            label.setText("");
                            label.setForeground(Color.red);
                        }
                    }
                    else{
                        JOptionPane.showMessageDialog(null , "Please enter full data !");
                        u = 0;
                        uname = "";
                        pw = "";
                        label.setText("");
                    }
                }
            }
        });
        back.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent e){
                if (e.getButton() == MouseEvent.BUTTON1)
                {
                    setVisible(false);
                    b = 1;
                    updateUI();
                }
            }
});
    }
}
